//
//  HJXMyinfoView.m
//  Catus
//
//  Created by 晓梦影 on 16/4/18.
//  Copyright © 2016年 黄金星. All rights reserved.
//

#import "HJXMyinfoView.h"
#import "HJXCoverButton.h"
#import "HJXTopMyInfoView.h"
#import "HJXBottomMyInfoView.h"



@implementation HJXMyinfoView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
//    self = [[[NSBundle mainBundle]loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil]lastObject];
    
    // 添加所有子控制器
    [self steUpAllSubviews];
    
    return self;
}


+ (instancetype)show
{
    // 创建一个透明的btn
    HJXCoverButton *coverBtn = [HJXCoverButton show];
    [coverBtn addTarget:self action:@selector(closeMyInfoV:) forControlEvents:UIControlEventTouchDown];
    // 个人信息页显示在btn制定位置上
    HJXMyinfoView *view = [[HJXMyinfoView alloc]initWithFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width * 0.7, [UIScreen mainScreen].bounds.size.height * 0.7)];
    view.backgroundColor = [UIColor whiteColor];
    [coverBtn addSubview:view];
    
    return view;
    
}
/**
 *  关闭个人信息主页 ---> self == HJXMyinfoView 当前是类方法
 *
 *  @param btn 遮盖按钮
 */
+ (void)closeMyInfoV:(UIButton *)btn
{
    // 移除遮盖按钮 --> 将遮盖按钮和个人信息页一起移除
    // 移除遮盖按钮
    for (UIView *view in [UIApplication sharedApplication].keyWindow.subviews) {
        
        if ([view isKindOfClass:[HJXCoverButton class]]) {
            [view removeFromSuperview];
        }
    }
}

#pragma mark - 添加所有子控制器
- (void)steUpAllSubviews
{
    // 添加上半部View
    HJXTopMyInfoView *topV = [[HJXTopMyInfoView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height * 0.25)];
    topV.backgroundColor = [UIColor orangeColor];
    [self addSubview:topV];
    
    // 添加下半部分View
    HJXBottomMyInfoView *bottomV = [[HJXBottomMyInfoView alloc]initWithFrame:CGRectMake(0,self.height * 0.25, self.width, self.height * 0.75)];
    [self addSubview:bottomV];
    
    
}

@end
